package com.tang.algorithm.doublePointer;

/**
 * @author tlm
 * @Description
 * @date 2020/7/9 6:55 下午
 */
public class LeetCode167 {
	public static void main(String[] args) {
		int[] a = { 2, 7, 11, 15 };
		int[] res = twoSum(a, 9);
		for (int re : res) {
			System.out.println(re);
		}
	}

	public static int[] twoSum(int[] numbers, int target) {
		int[] res = new int[2];
		int left = 0, right = numbers.length - 1;

		while (left < right) {
			int sum = numbers[left]+numbers[right];
			if(sum>target) right--;
			else if(sum<target) left++;
			else {
				res[0]=left+1;
				res[1]=right+1;
				break;
			}


		}

		return res;
	}
}
